package androidx.test.espresso.action;

import android.os.Build;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
import androidx.test.espresso.UiController;
import androidx.test.espresso.action.MotionEvents;
import androidx.test.espresso.action.Tapper;
import androidx.test.espresso.core.internal.deps.guava.base.Preconditions;
import java.lang.reflect.InvocationTargetException;

/* loaded from: classes.dex */
public enum Tap implements Tapper {
    SINGLE { // from class: androidx.test.espresso.action.Tap.1
        @Override // androidx.test.espresso.action.Tapper
        public Tapper.Status sendTap(UiController uiController, float[] coordinates, float[] precision) {
            return sendTap(uiController, coordinates, precision, 0, 0);
        }

        @Override // androidx.test.espresso.action.Tapper
        public Tapper.Status sendTap(UiController uiController, float[] coordinates, float[] precision, int inputDevice, int buttonState) {
            Tapper.Status sendSingleTap = Tap.sendSingleTap(uiController, coordinates, precision, inputDevice, buttonState);
            if (Tapper.Status.SUCCESS == sendSingleTap) {
                uiController.loopMainThreadForAtLeast(ViewConfiguration.getTapTimeout() * 1.5f);
            }
            return sendSingleTap;
        }
    },
    LONG { // from class: androidx.test.espresso.action.Tap.2
        @Override // androidx.test.espresso.action.Tapper
        public Tapper.Status sendTap(UiController uiController, float[] coordinates, float[] precision) {
            return sendTap(uiController, coordinates, precision, 0, 0);
        }

        @Override // androidx.test.espresso.action.Tapper
        public Tapper.Status sendTap(UiController uiController, float[] coordinates, float[] precision, int inputDevice, int buttonState) {
            Preconditions.checkNotNull(uiController);
            Preconditions.checkNotNull(coordinates);
            Preconditions.checkNotNull(precision);
            MotionEvent motionEvent = MotionEvents.sendDown(uiController, coordinates, precision, inputDevice, buttonState).down;
            try {
                uiController.loopMainThreadForAtLeast(ViewConfiguration.getLongPressTimeout() * 1.5f);
                if (!MotionEvents.sendUp(uiController, motionEvent)) {
                    MotionEvents.sendCancel(uiController, motionEvent);
                    return Tapper.Status.FAILURE;
                }
                motionEvent.recycle();
                return Tapper.Status.SUCCESS;
            } finally {
                motionEvent.recycle();
            }
        }
    },
    DOUBLE { // from class: androidx.test.espresso.action.Tap.3
        @Override // androidx.test.espresso.action.Tapper
        public Tapper.Status sendTap(UiController uiController, float[] coordinates, float[] precision) {
            return sendTap(uiController, coordinates, precision, 0, 0);
        }

        @Override // androidx.test.espresso.action.Tapper
        public Tapper.Status sendTap(UiController uiController, float[] coordinates, float[] precision, int inputDevice, int buttonState) {
            Preconditions.checkNotNull(uiController);
            Preconditions.checkNotNull(coordinates);
            Preconditions.checkNotNull(precision);
            Tapper.Status sendSingleTap = Tap.sendSingleTap(uiController, coordinates, precision, inputDevice, buttonState);
            if (sendSingleTap != Tapper.Status.FAILURE) {
                if (Tap.DOUBLE_TAP_MIN_TIMEOUT > 0) {
                    uiController.loopMainThreadForAtLeast(Tap.DOUBLE_TAP_MIN_TIMEOUT);
                }
                Tapper.Status sendSingleTap2 = Tap.sendSingleTap(uiController, coordinates, precision, inputDevice, buttonState);
                if (sendSingleTap2 == Tapper.Status.FAILURE) {
                    return Tapper.Status.FAILURE;
                }
                if (sendSingleTap2 == Tapper.Status.WARNING || sendSingleTap == Tapper.Status.WARNING) {
                    return Tapper.Status.WARNING;
                }
                return Tapper.Status.SUCCESS;
            }
            return Tapper.Status.FAILURE;
        }
    };
    
    private static final int DOUBLE_TAP_MIN_TIMEOUT;
    private static final String TAG = Tap.class.getSimpleName();

    static {
        int i = 0;
        if (Build.VERSION.SDK_INT > 18) {
            try {
                i = ((Integer) ViewConfiguration.class.getDeclaredMethod("getDoubleTapMinTime", new Class[0]).invoke(null, new Object[0])).intValue();
            } catch (IllegalAccessException e) {
                Log.w(TAG, "Unable to query double tap min time!", e);
            } catch (NoSuchMethodException e2) {
                Log.w(TAG, "Expected to find getDoubleTapMinTime", e2);
            } catch (InvocationTargetException e3) {
                Log.w(TAG, "Unable to query double tap min time!", e3);
            }
        }
        DOUBLE_TAP_MIN_TIMEOUT = i;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static Tapper.Status sendSingleTap(UiController uiController, float[] coordinates, float[] precision, int inputDevice, int buttonState) {
        Preconditions.checkNotNull(uiController);
        Preconditions.checkNotNull(coordinates);
        Preconditions.checkNotNull(precision);
        MotionEvents.DownResultHolder sendDown = MotionEvents.sendDown(uiController, coordinates, precision, inputDevice, buttonState);
        try {
            if (MotionEvents.sendUp(uiController, sendDown.down)) {
                sendDown.down.recycle();
                return sendDown.longPress ? Tapper.Status.WARNING : Tapper.Status.SUCCESS;
            }
            Log.d(TAG, "Injection of up event as part of the click failed. Send cancel event.");
            MotionEvents.sendCancel(uiController, sendDown.down);
            return Tapper.Status.FAILURE;
        } finally {
            sendDown.down.recycle();
        }
    }
}
